'use strict'
const PanelInfo = require('../model/5/panel');
const detectParam = require('../detecParam1')
class E {

    constructor () {
    }
    createPanelInfo (paneInfo) {
        // console.log(paneInfo.panelId);
        this.createPanelInfo(paneInfo);
    }
    createPanelInfo (paneInfo) {
        const panel = {
            uid: paneInfo.uid,
            panel_id: paneInfo.panelId,
            flaw_count: 0,
            is_ok: 1,
            length_md: paneInfo.length_md,
            length_cd: paneInfo.length_cd,
            save_path: "http://192.168.1.200:5555/jingdu.jpg",
            gen_time: paneInfo.startTime,
            gen_time_str: this.formatDate(paneInfo.startTime),
            checked: 0,
            detectParam: `${JSON.stringify([])}`
        }
        this.uploadInfo(PanelInfo, panel, 'CF_精度检测');
    }
    /**
     * 
     * @param {时间戳} date 
     * @returns 格式化后的时间
     */
     formatDate(date) {
        let time = new Date(date);
        let minites = time.getMinutes() < 10 ? `0${time.getMinutes()}` : time.getMinutes();
        let seconds = time.getSeconds() < 10 ? `0${time.getSeconds()}` : time.getSeconds();
        return `${time.toLocaleDateString()} ${time.getHours()}:${minites}:${seconds}`;
    }
    // 上传
    async uploadInfo (operater, jobInfo, tableName) {
        try {
            let res = await operater.upload(jobInfo);
            if (res.length || res.dataValues) {
                console.log(`${tableName} sucess`);
            }
        } catch (error) {
            console.log(error);
        }
    }
    static getInstance () {
        return new E();
    }
}

module.exports =  E.getInstance();